package com.ruoyi.project.system.list.controller;

import java.util.Arrays;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.list.domain.AccList;
import com.ruoyi.project.system.list.service.IAccListService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2022-05-06
 */
@Controller
@RequestMapping("/system/list")
public class AccListController extends BaseController
{
    private String prefix = "system/list";

    @Autowired
    private IAccListService accListService;

    @RequiresPermissions("system:list:view")
    @GetMapping()
    public String list()
    {
        return prefix + "/list";
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("system:list:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AccList accList)
    {
        startPage();
        List<AccList> list = accListService.selectAccListList(accList);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("system:list:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AccList accList)
    {
        List<AccList> list = accListService.selectAccListList(accList);
        ExcelUtil<AccList> util = new ExcelUtil<AccList>(AccList.class);
        return util.exportExcel(list, "【请填写功能名称】数据");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("system:list:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AccList accList)
    {
        return toAjax(accListService.insertAccList(accList));
    }

    /**
     * 修改【请填写功能名称】
     */
    @RequiresPermissions("system:list:edit")
    @GetMapping("/edit/{acc}")
    public String edit(@PathVariable("acc") String acc, String type, ModelMap mmap)
    {
        System.out.println(acc);
        System.out.println(type);
        if(acc.split(",").length==1&&!"types".equals(type)){
            AccList accList = accListService.selectAccListByAccAndType(acc,type);
            mmap.put("accList", accList);
        }else{
            AccList accList =new AccList();
            accList.setAcc(acc);
            mmap.put("accList",accList);
        }

        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("system:list:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AccList accList)
    {

        return toAjax(accListService.updateAccList(accList));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("system:list:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String acc,String type)
    {
        return toAjax(accListService.deleteAccListByAcc(acc,type));
    }

//    @RequiresPermissions("system:list:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @GetMapping( "/updateAll")
    @ResponseBody
    public AjaxResult updateAll(@RequestParam("accList") List<AccList> accList)
    {
        return toAjax(accListService.updateAll(accList));
    }

}
